using Microsoft.Win32;
using SM.core;
using SM.sys;
using SS.core;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace SS
{
	internal static class Program
	{
		public static DataSet dsBisImpoter;
		public static bool registed = false;
		public static string lenAffterDecimal;
		public static string strConnectionString;
		public static Dictionary<string, string> listNational = new Dictionary<string, string>();
		public static Dictionary<string, string> listProvider = new Dictionary<string, string>();
		[STAThread]
		private static void Main()
		{
			bisImporter bisImporter = new bisImporter();
			Program.dsBisImpoter = bisImporter.fillDataBisImpoter();
			National.getListNational();
			National.getListProvider();
			string text = ConfigurationSettings.AppSettings["ServerName"].ToString();
			string text2 = ConfigurationSettings.AppSettings["UserID"].ToString();
			string text3 = ConfigurationSettings.AppSettings["PassWord"].ToString();
			string text4 = ConfigurationSettings.AppSettings["DataBase"].ToString();
			Program.strConnectionString = string.Concat(new string[]
			{
				"Server=",
				text,
				"; Initial Catalog=",
				text4,
				"; User Id=",
				text2,
				"; pwd=",
				text3,
				";"
			});
			Func func = new Func();
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			try
			{
				sqlConnection.Open();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
				FrmCongif frmCongif = new FrmCongif();
				frmCongif.ShowDialog();
			}
			try
			{
				RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\TVSGPP", true);
				Program.lenAffterDecimal = registryKey.GetValue("LenNumformat").ToString().Trim();
				registryKey.Close();
			}
			catch
			{
				Program.lenAffterDecimal = "{0:0,0.00}";
			}
			try
			{
				Regis regis = new Regis();
				string text5 = regis.InsertInfo("Win32_Processor");
				string cDKey = regis.GetCDKey(text5.Trim());
				int num = regis.GetCountBill1() + regis.GetCountBill2();
				if (cDKey.ToUpper() == regis.GetSerial().ToUpper() || num < 30)
				{
					Application.EnableVisualStyles();
					Application.SetCompatibleTextRenderingDefault(false);
					frmLogin frmLogin = new frmLogin();
					frmLogin.ShowDialog();
					if (frmLogin.OK)
					{
						new FrmMain
						{
							UserName = frmLogin.UserName,
							FullName = frmLogin.FullName,
							Password = frmLogin.Password,
							LogStatus = true
						}.ShowDialog();
					}
				}
				else
				{
					try
					{
						FrmRegister frmRegister = new FrmRegister();
						frmRegister.ShowDialog();
					}
					catch
					{
					}
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				Application.Exit();
			}
		}
	}
}
